package com.wisdomparking.control.app;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wisdomparking.bean.Parking;
import com.wisdomparking.bean.User;
import com.wisdomparking.config.result.Message;
import com.wisdomparking.control.BaseController;
import com.wisdomparking.service.ParkingService;
import com.wisdomparking.service.UserService;
import com.wisdomparking.tools.ToolValid;

/**
 * 车场中心
 */
@RestController
@RequestMapping("/app/parkingCenter")
public class ParkingController extends BaseController{
	
	@Autowired ParkingService parkingService;
	@Autowired UserService userService;
	
	
	/**
	 * 获取车场停车位信息
	 * 
	 * @param name
	 * @return
	 */
	@RequestMapping("/getParkingSurplusPlace")
	public Message getParkingDetail(String name, HttpServletRequest request){
		Parking parking = parkingService.getParkingByName(name);
		Map<String, Object> map = null;
		if(ToolValid.isNotNull(parking)){
			map = new HashMap<>();
			map.put("parkingTotalA", parking.getParkingTotalA());
			map.put("surplusLargeVehicleA", parking.getSurplusLargeVehicleA());
			map.put("surplusLightdutyVehicleA", parking.getSurplusLightdutyVehicleA());
			map.put("chargingA", parking.getChargingA());
			map.put("parkingTotalB", parking.getParkingTotalB());
			map.put("surplusLargeVehicleB", parking.getSurplusLargeVehicleB());
			map.put("surplusLightdutyVehicleB", parking.getSurplusLightdutyVehicleB());
			map.put("chargingB", parking.getChargingB());
			
			int defaultVehicleType = 3;
			String userId = request.getParameter("userId");
			
			if(ToolValid.isNotEmpty(userId)){
				User user = userService.getUser(Integer.parseInt(userId));
				if(ToolValid.isNotNull(user)){
					defaultVehicleType = user.getDefaultVehicleType();
				}
			}
			
			map.put("defaultVehicleType", defaultVehicleType);
		}
		return new Message(map);
	}
	
}
